home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_9.zip
/
GMAIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-27
|
24KB
|
846 lines
/*
* Copyright (C) 1985-1992 New York University
*
* This file is part of the Ada/Ed-C system. See the Ada/Ed README file for
* warranty (none) and distribution info and also the GNU General Public
* License for more details.
*/
#define GEN
#include <stdio.h>
#include <ctype.h>
#include "hdr.h"
#include "vars.h"
#include "gvars.h"
#include "libhdr.h"
#include "segment.h"
#include "ifile.h"
#include "dbxp.h"
#include "packp.h"
#include "g0ap.h"
#include "dclmapp.h"
#include "arithp.h"
#include "axqrp.h"
#include "axqwp.h"
#include "genp.h"
#include "segmentp.h"
#include "expandp.h"
#include "procp.h"
#include "libp.h"
#include "libfp.h"
#include "librp.h"
#include "libwp.h"
#include "readp.h"
#include "setp.h"
#include "initp.h"
#include "glibp.h"
#include "gutilp.h"
#include "miscp.h"
#include "gmiscp.h"
#include "gmainp.h"
static void fold_upper(char *);
static void preface();
static void exitf(int);
static void init_gen();
static void finit_gen();
IFILE *AISFILE, *AXQFILE, *STUBFILE, *LIBFILE, *TREFILE;
int list_unit_0 = 0; /* set by '0' option to list unit 0 structure */
int peep_option = 1; /* on for peep_hole optimization */
extern Segment CODE_SEGMENT, DATA_SEGMENT, DATA_SEGMENT_MAIN;
extern Tuple units_in_compilation;
extern Segment VARIANT_TABLE, FIELD_TABLE ;
#ifdef DEBUG
extern int zpadr_opt; /* not for EXPORT */
#endif
char *lib_name;
/*
#include "avl.c"
*/
main (int argc, char **argv)
{
Node node_new ();
int c, i, n;
int errflg = 0, nobuffer = 0, mflag = 0;
extern int optind;
extern char *optarg;
char *fname, *tfname;
char *t_name;
/*
AVL_GET_DESC();
_outtext(" Generating Code.");
*/
AISFILE = (IFILE *)0;
AXQFILE = (IFILE *)0;
LIBFILE = (IFILE *)0;
STUBFILE = (IFILE *)0;
TREFILE = (IFILE *)0;
MAINunit = "";
interface_files = "";
while ((c = getopt (argc, argv, "g:l:m:ni:")) != EOF)
/* user:
* g debugging, followed by list of options:
* 0 show structure of unit 0
* b do not buffer standard output
* e flag signalling errors in the parsing phase
* g list generated code
* l show line numbers in generated code
* p compiling predef units
* z call trapini to initialize traps
* i to specify object files and librairies for pragma interface
* l using library
* m main unit name
* n new library
*/
switch (c) {
case 'i':
interface_files = strjoin(interface_files, optarg);
interface_files = strjoin(interface_files, " ");
break;
case 'l': /* using existing library */
lib_name= emalloc((unsigned) strlen(optarg) + 1);
strcpy(lib_name, optarg);
break;
case 'm': /* specify main unit name */
MAINunit = malloc((unsigned) strlen(optarg)+1);
strcpy(MAINunit, optarg);
fold_upper(MAINunit);
break;
case 'n': /* indicates new library */
new_library = TRUE;
break;
case 'g': /* gen debug options */
n = strlen(optarg);
for (i = 0; i < n; i++) {
switch((int)optarg[i]) {
#ifdef DEBUG
case 'a':
zpadr_opt = 0; /* do not print addresses in zpadr */
break;
#endif
case 'g':
list_code++;
break;
case 'l':
line_option++;
break;
case 'p': /* compiling predef units */
printf("compiling predef\n");
compiling_predef++ ;
break;
#ifdef DEBUG
case 'b': /* do not buffer output */
nobuffer++;
break;
case 'd': /* force debugging output */
debug_flag++;
break;
case 'e':
errors = TRUE;
break;
case 'o': /* disable optimization (peep) */
peep_option = 0;
break;
case '0': /* read trace including unit 0 */
list_unit_0++;
break;
case 'z':
trapini();
break;
#endif
}
}
break;
case '?':
errflg++;
}
fname = (char *)0;
if (optind < argc)
fname = argv[optind];
if (fname == (char *)0) errflg++;
if (errflg) {
fprintf (stderr, "Usage: adagen -aAbglnmMnrstw file\n");
exitp(RC_ABORT);
}
tup_init(); /* initialize set and tuple procedures */
FILENAME = (fname != (char *)0) ? strjoin(fname, "") : fname;
if (compiling_predef) {
PREDEFNAME = "";
}
else
PREDEFNAME = predef_env();
if (nobuffer) {
setbuf (stdout, (char *) 0); /* do not buffer output (for debug) */
}
rat_init(); /* initialize arithmetic and rational package*/
dstrings_init(2048, 256); /* initialize dstrings package */
init_sem();
DATA_SEGMENT_MAIN = main_data_segment();
aisunits_read = tup_new(0);
init_symbols = tup_exp(init_symbols, seq_symbol_n);
for (i = 1; i <= seq_symbol_n; i++)
init_symbols[i] = seq_symbol[i];
t_name = libset(lib_name);
num_predef_units = (compiling_predef) ? 0 : init_predef();
/*
* When the separate compilation facility is being used all references to
* AIS files will be made via the directory in LIBFILE. AISFILENAME is set
* to a number.
*/
if (compiling_predef)
AISFILENAME = "0";
else if (new_library)
AISFILENAME = "1";
else
AISFILENAME = lib_aisname(); /* retrieve name from library */
/* open the appropriate files using the suffix .axq for axq files and
* .trc for tree file.
*
* Open MESSAGEFILE with suffixe ".msg" if a file name specified;
* otherwise, if a file name not required, and one is not given,
* used stderr.
*/
AXQFILE = ifopen(AISFILENAME, "axq", "w", 0);
MSGFILE = (FILENAME != (char *) 0 ) ? efopenl(FILENAME, "msg", "a", "t") :
stderr;
/* delete any existing st2 file for this AISFILENAME since it is now
* obsolete
*/
ifdelete(strjoin(AISFILENAME, ".st2"));
/* unbuffer output for debugging purposes */
if (MSGFILE != stderr)
setbuf(MSGFILE, (char *) 0);
preface();
/* Code formerly procedure finit() in init.c is now put here directly */
if (!errors) {
write_glib();
cleanup_files();
}
if (compiling_predef) printf("Compilation of predef complete\n");
exitf(RC_SUCCESS);
}
static void fold_upper(char *s) /*;fold_upper*/
{
register char c;
while (c = *s) {
if (islower(c)) *s = toupper(c);
s++;
}
}
void fold_lower(char *s) /*;fold_lower*/
{
register char c;
while (c = *s) {
if (isupper(c)) *s = tolower(c);
s++;
}
}
/* In the SETL version, preface has the global declarations of macros and
* variables. In the C version, the global variables are defined in gvars.ch
* (from which gvars.c and gvars.h are derived); macros and structure
* declarations are in ghdr.h.
* This file is retained for now to hold parts of code not moved to other
* files in the C version.
*
* pref2 - part 2 of preface: global variables, procedure declarations
*
* Conventions for capitalization.
* The SETL version uses upper case names for some procedures, macros
* and global variables. Since case conventions are not enforced by the
* SETL compiler, there are cases where the same name is written more
* than one way, differing only in case.
* In C, we will use upper case for macro names, defined constants and most
* of the global variables, especially, the variables defined here. Where
* mixed-case usage is known to exist in the SETL version, such will be
* indicated by writine (mixed-case) after the variable name.
*/
/* macros moved to hdr.c*/
static Set units_loaded;
static void preface() /*;preface*/
{
int indx, last_index, i, rootseq, body_number;
Node first_node, unit_node;
Tuple aisread_tup, tup;
int unit_number_now;
struct unit *pUnit;
char *spec_nam;
aisread_tup = tup_new(0);
initialize_1();
/* 1- Load PREDEF */
TASKS_DECLARED = FALSE;
/* 2- Generate user program */
initialize_2();
if (gen_option) {
/* read all the units in file, aisunits_read is tuple of unit names of
* units found in file.
*/
TREFILE = ifopen(AISFILENAME, "aic", "r", 0);
last_index = last_comp_index(TREFILE);
indx = 0;
units_loaded = set_new(0);
for (indx = 1; indx <= last_index; indx++) {
unit_name = read_ais(AISFILENAME, TRUE, (char *) 0, indx, TRUE);
TREFILE = ifopen(AISFILENAME, "trc", "r", 0);
load_tre(TREFILE, indx);
unit_number_now = unit_numbered(unit_name);
pUnit = pUnits[unit_number_now];
seq_node_n = pUnit->treInfo.nodeCount;
seq_node = tup_new(seq_node_n);
/* set seq_symbol to corresponding values